// pages/microShop_ShopKeeperCenter/microShop_ShopKeeperCenter.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    language: "",
    username1: "微店名称",
    level1: "级别",
    share1: "0",
    share2: "0",
    totalTicket: 0,
    totalShareMoney: 0,
    userImg: "",
    orderData: "",
    shareData: "",
    shop_id: "",
    shoplang: "",
    ban_open: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.shop_id) {
      this.setData({
        shop_id: options.shop_id,
      });
    }
    this.checkrouter();
    this.getJson();
  },
  checkrouter() {
    try {
      // 推广中心是否开启该功能，没开启跳转到指定路径
      let basic_info = wx.getStorageSync("yz_basic_info");
      let stop_info = basic_info.popularize_page.mini.vue_route;
      for (let i = 0; i < stop_info.length; i++) {
        if (stop_info[i] == "microShop_ShopKeeperCenter") {
          console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");
          // let suburl = basic_info.popularize_page.mini.mini_url.substr(1);
          wx.showToast({
            title: "未开启推广权限",
            duration: 1000,
            icon: "none",
            success: function () {
              setTimeout(() => {
                wx.redirectTo({
                  url: basic_info.popularize_page.mini.mini_url,
                });
              }, 1000);
            },
          });
          return;
        }
      }
    } catch (e) {
      console.log(e);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({ language: language.en });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  navRqCode() {
    wx.navigateTo({
      url: `/packageC/microshop/microshop_qrCode/microshop_qrCode?shop_id=${this.data.shop_id}`
    });
  },
  onShareAppMessage: function () {},
  onconfirm(e) {
    this.setData({
      ban_open: false,
    });
  },
  gomicroShopOrderDetail() {
    // 'microShop_orderDetail',{date:'-1'}
  },
  getJson() {
    let that = this;
    let urlStr = app.getNetAddresss(
      "plugin.micro.frontend.controllers.MicroShop.index"
    );
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let shopId= res.data?.micro_shop_data?.shop_id;
          if(!shopId) {
            wx.showModal({
              title: '提示',
              content: '您暂时无微店,点击确定申请？',
              success(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/packageC/microshop/microShop_apply/microShop_apply'
                  });
                } else if (res.cancel) {
                  wx.navigateBack({
                    delta: 1
                  });
                }
              }
            });
          }
          that.setData({
            userImg: res.data.micro_shop_data.shop_avatar,
            username1: res.data.micro_shop_data.shop_name,
            level1: res.data.micro_shop_data.level_name,
            share1: res.data.micro_shop_data.bonus_ratio,
            share2: res.data.micro_shop_data.agent_bonus_ratio,
            shop_id:res.data?.micro_shop_data?.shop_id,
            totalTicket: res.data.order_data.order_total,
            totalShareMoney: res.data.bonus_log_data.bonus_total,
            shareData: res.data.bonus_log_data,
            orderData: res.data.order_data,
          });
          if (res.data.is_ban == 1) {
            that.setData({
              ban_open: true,
            });
          }
          if (res.data.lang) {
            that.setData({
              shoplang: res.data.lang,
            });
          }
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  gomicroShopbaseinfo() {
    wx.navigateTo({
      url:
        "/packageC/microshop/microShop_baseinfo/microShop_baseinfo?shop_id=" +
        this.data.shop_id,
    });
  },
  gomicroShop_home() {
    wx.reLaunch({
      url:
        "/packageC/microshop/microShop_home/microShop_home?shop_id=" +
        this.data.shop_id,
    });
  },
  gomicroShop_apply() {
    wx.navigateTo({
      url: "/packageC/microshop/microShop_apply/microShop_apply",
    });
  },
  gomicroShopShareList(e) {
    let date = e.currentTarget.dataset.date;
    wx.navigateTo({
      url:
        "/packageC/microshop/microShop_shareList/microShop_shareList?date=" +
        date,
    });
  },
  microShopAddCategory() {
    wx.navigateTo({
      url:"/packageC/microshop/micro_shop_add_category/micro_shop_add_category?shop_id=" + this.data.shop_id,
    });
  },
});
